﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace BACKOFFICE
{
    public partial class EmployeeSchedule : DevExpress.XtraEditors.XtraUserControl
    {
        Dictionary<string, string> employeeList = new Dictionary<string, string>();
        Dictionary<string, List<TextEdit>> txtBoxes = new Dictionary<string, List<TextEdit>>();
        int lblx = 3;
        int lbly = 121;

        int txtx = 125;
        int txty = 118;

        public EmployeeSchedule()
        {
            InitializeComponent();
        }

        private void EmployeeSchedule_Load(object sender, EventArgs e)
        {
            foreach (DataRow item in DataTableClass.JobTitles.Rows)
            {
                cbJobTitles.Properties.Items.Add(item["JobTitles"].ToString().Trim());
            }
        }

        private void cbJobTitles_SelectedValueChanged(object sender, EventArgs e)
        {
            LoadEmployees(cbJobTitles.SelectedText);
        }

        void LoadEmployees(string Jobtitle)
        {
            LabelControl WeekDayName = new LabelControl();
            WeekDayName.Text = "Monday";
            WeekDayName.Name = "lbl" + "Monday";
            WeekDayName.Appearance.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold);
            WeekDayName.Location = new Point(168 + 21, txty - 15);
            //lbly = lbly + 28;
            this.Controls.Add(WeekDayName);

            LabelControl WeekDayName1 = new LabelControl();
            WeekDayName1.Text = "Tuesday";
            WeekDayName1.Name = "lbl" + "Tuesday";
            WeekDayName1.Appearance.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold);
            WeekDayName1.Location = new Point(354 + 21, txty - 15);
            //lbly = lbly + 28;
            this.Controls.Add(WeekDayName1);

            LabelControl WeekDayName2 = new LabelControl();
            WeekDayName2.Text = "Wednesday";
            WeekDayName2.Name = "lbl" + "Wednesday";
            WeekDayName2.Appearance.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold);
            WeekDayName2.Location = new Point(540 + 19, txty - 15);
            //lbly = lbly + 28;
            this.Controls.Add(WeekDayName2);

            LabelControl WeekDayName3 = new LabelControl();
            WeekDayName3.Text = "Thursday";
            WeekDayName3.Name = "lbl" + "Thursday";
            WeekDayName3.Appearance.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold);
            WeekDayName3.Location = new Point(726 + 21, txty - 15);
            //lbly = lbly + 28;
            this.Controls.Add(WeekDayName3);

            LabelControl WeekDayName4 = new LabelControl();
            WeekDayName4.Text = "Friday";
            WeekDayName4.Name = "lbl" + "Friday";
            WeekDayName4.Appearance.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold);
            WeekDayName4.Location = new Point(912 + 21, txty - 15);
            //lbly = lbly + 28;
            this.Controls.Add(WeekDayName4);

            LabelControl WeekDayName5 = new LabelControl();
            WeekDayName5.Text = "Saturday";
            WeekDayName5.Name = "lbl" + "Saturday";
            WeekDayName5.Appearance.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold);
            WeekDayName5.Location = new Point(1098 + 21, txty - 15);
            //lbly = lbly + 28;
            this.Controls.Add(WeekDayName5);

            LabelControl WeekDayName6 = new LabelControl();
            WeekDayName6.Text = "Sunday";
            WeekDayName6.Name = "lbl" + "Sunday";
            WeekDayName6.Appearance.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold);
            WeekDayName6.Location = new Point(1284 + 21, txty - 15);
            //lbly = lbly + 28;
            this.Controls.Add(WeekDayName6);

            foreach (DataRow item in DataTableClass.EmployeeInfo.Rows)
            {
                if (item["EmployeeTitle"].ToString().Trim() == cbJobTitles.SelectedText)
                {
                    employeeList.Add(item["EmployeeID"].ToString().Trim(), (item["EmployeeFirstName"].ToString().Trim() + " " + item["EmployeeLastName"].ToString().Trim()));
                    LoadDataSetup((item["EmployeeFirstName"].ToString().Trim() + " " + item["EmployeeLastName"].ToString().Trim()));
                }
            }
        }

        void LoadDataSetup(string EmpName)
        {
            LabelControl EmployeeNameLabel = new LabelControl();

            EmployeeNameLabel.Text = EmpName;
            EmployeeNameLabel.Name = "lbl" + EmpName;
            EmployeeNameLabel.Location = new Point(lblx, lbly);
            lbly = lbly + 28;
            this.Controls.Add(EmployeeNameLabel);

            TextEdit daytextbox = new TextEdit();
            daytextbox.Name = "txt" + EmpName + "MondayAM";
            daytextbox.Location = new Point(txtx, txty);
            daytextbox.Width = 80;
            this.Controls.Add(daytextbox);
            txtx = txtx + 86;
            
            TextEdit daytextbox2 = new TextEdit();
            daytextbox2.Name = "txt" + EmpName + "MondayPM";
            daytextbox2.Location = new Point(txtx, txty);
            daytextbox2.Width = 80;
            this.Controls.Add(daytextbox2);
            txtx = txtx + 100;

            TextEdit daytextbox3 = new TextEdit();
            daytextbox3.Name = "txt" + EmpName + "TuesdayAM";
            daytextbox3.Location = new Point(txtx, txty);
            daytextbox3.Width = 80;
            this.Controls.Add(daytextbox3);
            txtx = txtx + 86;
            
            TextEdit daytextbox4 = new TextEdit();
            daytextbox4.Name = "txt" + EmpName + "TuesdayPM";
            daytextbox4.Location = new Point(txtx, txty);
            daytextbox4.Width = 80;
            this.Controls.Add(daytextbox4);
            txtx = txtx + 100;

            TextEdit daytextbox5 = new TextEdit();
            daytextbox5.Name = "txt" + EmpName + "WednesdayAM";
            daytextbox5.Location = new Point(txtx, txty);
            daytextbox5.Width = 80;
            this.Controls.Add(daytextbox5);
            txtx = txtx + 86;
            
            TextEdit daytextbox6 = new TextEdit();
            daytextbox6.Name = "txt" + EmpName + "WednesdayPM";
            daytextbox6.Location = new Point(txtx, txty);
            daytextbox6.Width = 80;
            this.Controls.Add(daytextbox6);
            txtx = txtx + 100;

            TextEdit daytextbox7 = new TextEdit();
            daytextbox7.Name = "txt" + EmpName + "ThursdayAM";
            daytextbox7.Location = new Point(txtx, txty);
            daytextbox7.Width = 80;
            this.Controls.Add(daytextbox7);
            txtx = txtx + 86;
            
            TextEdit daytextbox8 = new TextEdit();
            daytextbox8.Name = "txt" + EmpName + "ThursdayPM";
            daytextbox8.Location = new Point(txtx, txty);
            daytextbox8.Width = 80;
            this.Controls.Add(daytextbox8);
            txtx = txtx + 100;

            TextEdit daytextbox9 = new TextEdit();
            daytextbox9.Name = "txt" + EmpName + "FridayAM";
            daytextbox9.Location = new Point(txtx, txty);
            daytextbox9.Width = 80;
            this.Controls.Add(daytextbox9);
            txtx = txtx + 86;
            
            TextEdit daytextbox10 = new TextEdit();
            daytextbox10.Name = "txt" + EmpName + "FridayPM";
            daytextbox10.Location = new Point(txtx, txty);
            daytextbox10.Width = 80;
            this.Controls.Add(daytextbox10);
            txtx = txtx + 100;

            TextEdit daytextbox11 = new TextEdit();
            daytextbox11.Name = "txt" + EmpName + "SaturdayAM";
            daytextbox11.Location = new Point(txtx, txty);
            daytextbox11.Width = 80;
            this.Controls.Add(daytextbox11);
            txtx = txtx + 86;
            
            TextEdit daytextbox12 = new TextEdit();
            daytextbox12.Name = "txt" + EmpName + "SaturdayPM";
            daytextbox12.Location = new Point(txtx, txty);
            daytextbox12.Width = 80;
            this.Controls.Add(daytextbox12);
            txtx = txtx + 100;

            TextEdit daytextbox13 = new TextEdit();
            daytextbox13.Name = "txt" + EmpName + "SundayAM";
            daytextbox13.Location = new Point(txtx, txty);
            daytextbox13.Width = 80;
            this.Controls.Add(daytextbox13);
            txtx = txtx + 86;
          
            TextEdit daytextbox14 = new TextEdit();
            daytextbox14.Name = "txt" + EmpName + "SundayPM";
            daytextbox14.Location = new Point(txtx, txty);
            daytextbox14.Width = 80;
            this.Controls.Add(daytextbox14);
            txtx = txtx + 100;

            txtx = 125;
            txty = txty + 28;
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {

            foreach (KeyValuePair<string, string> item in employeeList)
            {
                TextEdit MondayAM = new TextEdit();
                TextEdit MondayPM = new TextEdit();
                TextEdit TuesdayAM = new TextEdit();
                TextEdit TuesdayPM = new TextEdit();
                TextEdit WednesdayAM = new TextEdit();
                TextEdit WednesdayPM = new TextEdit();
                TextEdit ThursdayAM = new TextEdit();
                TextEdit ThursdayPM = new TextEdit();
                TextEdit FridayAM = new TextEdit();
                TextEdit FridayPM = new TextEdit();
                TextEdit SaturdayAM = new TextEdit();
                TextEdit SaturdayPM = new TextEdit();
                TextEdit SundayAM = new TextEdit();
                TextEdit SundayPM = new TextEdit();

                
                foreach (Control Boxes in this.Controls)
                {
                    if(Boxes.Name.Contains(item.Value))
                    {
                        if (Boxes.Name.Contains("MondayAM"))
                        {
                            MondayAM = Boxes as DevExpress.XtraEditors.TextEdit;

                        }
                        if (Boxes.Name.Contains("MondayPM"))
                        {
                            MondayPM = Boxes as DevExpress.XtraEditors.TextEdit;
                        }
                        if (Boxes.Name.Contains("TuesdayAM"))
                        {
                            TuesdayAM = Boxes as DevExpress.XtraEditors.TextEdit;

                        }
                        if (Boxes.Name.Contains("TuesdayPM"))
                        {
                            TuesdayPM = Boxes as DevExpress.XtraEditors.TextEdit;
                        }
                        if (Boxes.Name.Contains("WednesdayAM"))
                        {
                            WednesdayAM = Boxes as DevExpress.XtraEditors.TextEdit;

                        }
                        if (Boxes.Name.Contains("WednesdayPM"))
                        {
                            WednesdayPM = Boxes as DevExpress.XtraEditors.TextEdit;
                        }
                        if (Boxes.Name.Contains("ThursdayAM"))
                        {
                            ThursdayAM = Boxes as DevExpress.XtraEditors.TextEdit;

                        }
                        if (Boxes.Name.Contains("ThursdayPM"))
                        {
                            ThursdayPM = Boxes as DevExpress.XtraEditors.TextEdit;
                        }
                        if (Boxes.Name.Contains("FridayAM"))
                        {
                            FridayAM = Boxes as DevExpress.XtraEditors.TextEdit;

                        }
                        if (Boxes.Name.Contains("FridayPM"))
                        {
                            FridayPM = Boxes as DevExpress.XtraEditors.TextEdit;
                        }
                        if (Boxes.Name.Contains("SaturdayAM"))
                        {
                            SaturdayAM = Boxes as DevExpress.XtraEditors.TextEdit;

                        }
                        if (Boxes.Name.Contains("SaturdayPM"))
                        {
                            SaturdayPM = Boxes as DevExpress.XtraEditors.TextEdit;
                        }
                        if (Boxes.Name.Contains("SundayAM"))
                        {
                            SundayAM = Boxes as DevExpress.XtraEditors.TextEdit;

                        }
                        if (Boxes.Name.Contains("SundayPM"))
                        {
                            SundayPM = Boxes as DevExpress.XtraEditors.TextEdit;
                            
                        }
                    }
                }
                try
                {
                    DataRow newCustomersRow = DataTableClass.EmployeeSchedule.NewRow();


                    newCustomersRow["WeekStartDate"] = dateEdit1.SelectedText;
                    newCustomersRow["EmployeeID"] = item.Key;
                    newCustomersRow["MondayAM"] = MondayAM.Text;
                    newCustomersRow["MondayPM"] = MondayPM.Text;
                    newCustomersRow["TuesdayAM"] = TuesdayAM.Text;
                    newCustomersRow["TuesdayPM"] = TuesdayPM.Text;
                    newCustomersRow["WednesdayAM"] = WednesdayAM.Text;
                    newCustomersRow["WednesdayPM"] = WednesdayPM.Text;
                    newCustomersRow["ThursdayAM"] = ThursdayAM.Text;
                    newCustomersRow["ThursdayPM"] = ThursdayPM.Text;
                    newCustomersRow["FridayAM"] = FridayAM.Text;
                    newCustomersRow["FridayPM"] = FridayPM.Text;
                    newCustomersRow["SaturdayAM"] = SaturdayAM.Text;
                    newCustomersRow["SaturdayPM"] = SaturdayPM.Text;
                    newCustomersRow["SundayAM"] = SundayAM.Text;
                    newCustomersRow["SundayPM"] = SundayPM.Text;


                    DataTableClass.EmployeeSchedule.Rows.Add(newCustomersRow);
                }
                catch (Exception E)
                {
                    MessageBox.Show(E.ToString());
                }

                //PrintingClass.EmpID = Convert.ToInt32(item.Key);
                //PrintingClass.PrintEmployeeSchedulePage();
            }


            //DataTableClass.SendDataToSqlServer(DataTableClass.EmployeeSchedule.TableName);
        }
        
    }

}
